package com.goldrepo.play;

import com.goldrepo.play.common.ApiResponse;
import com.goldrepo.play.common.ErrorResponse;
import com.goldrepo.play.service.ZYService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>Description: 接口</p>
 *
 * @author Goldrepo
 * @date 2022-05-11 18:31
 **/
@RestController
@RequestMapping("/api")
public class DemoController {

    @GetMapping("/start")
    public ApiResponse start(){
        Map result = service.start();
        return ApiResponse.success(ApiResponse.Status.SUCCESS, result);
    }

    @GetMapping("/random")
    public ApiResponse random(String start, String count){
        if(StringUtils.isBlank(start) || StringUtils.isBlank(count)){
            return ApiResponse.error(ApiResponse.Status.ERROR, new ErrorResponse("-1", "参数值不能为空"));
        }else{
            Map result = service.random(Integer.parseInt(start), Integer.parseInt(count));
            return ApiResponse.success(ApiResponse.Status.SUCCESS, result);
        }
    }

    @GetMapping("/msg")
    public ApiResponse msg(String code){
        if(StringUtils.isBlank(code)){
            return ApiResponse.error(ApiResponse.Status.ERROR, new ErrorResponse("-1", "参数值不能为空"));
        }else{
            Map result = service.msg(code);
            return ApiResponse.success(ApiResponse.Status.SUCCESS, result);
        }
    }

    @Resource
    private ZYService service;

}
